package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Controller
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/test1")  //访问路径
    public String hello1(){
        int i = 1/0;
        System.out.println("hello world");

        return "forward:/index.jsp"; // 跳转:/index.jsp
    }

    @RequestMapping("/test2") //访问路径
    public String hello2(){
        int i = 0;
        if(i == 0){
            throw new RuntimeException("这就是一个异常,自行处理");
        }
        System.out.println("hello c9");
        return "hello";//  跳转:/jsp/hello2.jsp
    }

    @RequestMapping("/test03")
    public String test03(HttpServletRequest request){
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        System.out.println("id:" + id);
        System.out.println("name:" + name);
        return "hello";
    }

    @RequestMapping("/test04")
    public String test04(Integer id , String name){
        System.out.println("id:" + id);
        System.out.println("name:" + name);
        return "hello";
    }

    @RequestMapping("/test05")
    public String test05(User user){
        System.out.println(user);
        return "hello";
    }

    @RequestMapping("/test06")
    public String test06(String[] hobby){
        System.out.println(Arrays.toString(hobby));
        return "hello";
    }
}
